package com.gitee.xmhzzz.component.web.intercepter;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.lang.Nullable;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
  * @ClassName
  * @Description
  * @Author wzq
  * @Date 2023/12/18 10:22
  * @Version 1.0
  */
public class UserInterceptor extends HandlerInterceptorAdapter
{
    private static final Logger LOGGER = LoggerFactory.getLogger(UserInterceptor.class);

    public UserInterceptor()
    {
        super();
    }

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
            throws Exception
    {
        // String userId = request.getHeader(AuthConstant.USER_ID_HEADER);
        // UserContext.setUserId(userId == null ? "" : userId);
        // String accountId = request.getHeader(AuthConstant.ACCOUNT_ID_HEADER);
        // String brandCode = request.getHeader(AuthConstant.BRAND_CODE_HEADER);
        // String roleId = request.getHeader(AuthConstant.ROLE_ID_HEADER);
        // String userCode = request.getHeader(AuthConstant.USER_CODE_HEADER);
        // BaseInfo baseInfo = new BaseInfo();
        // baseInfo.setAccountId(accountId);
        // baseInfo.setBrandCode(brandCode);
        // baseInfo.setUserCode(userCode);
        // baseInfo.setRoleId(roleId);
        // UserContext.setBaseInfo(baseInfo);
        // LOGGER.debug("userInterceptor userId ：{} ", userId);
        return super.preHandle(request, response, handler);
    }

    @Override
	public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
			@Nullable ModelAndView modelAndView) throws Exception {
        // UserContext.clear();
         super.postHandle(request, response, handler, modelAndView);
	}
}
